
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        2/12/2009
 * PROJECT:             MCWEBSTIE
 * PURPOSE:             websiteAdZoneDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using System.Data;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteAdZoneDAL
    {
        #region  Properties

        public static string FIELD_ADID = "AdID";
        public static string FIELD_ADNAME = "AdName";
        public static string FIELD_ADURL = "AdUrl";
        public static string FIELD_ADBEGINDATE = "AdBeginDate";
        public static string FIELD_ADENDDATE = "AdEndDate";
        public static string FIELD_ISACTIVE = "IsActive";
        public static string FIELD_ADPOSITION = "AdPosition";
        public static string FIELD_ADDESCRIPTION = "AdDescription";
        public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteAdZone
        /// </summary>
        /// <param name="AdID">Primary Keys</param>
        /// <returns>Collection of websiteAdZoneInfo</returns>
        public static websiteAdZoneInfo SelectOne(int AdID)
        {
            websiteAdZoneInfo _websiteAdZoneInfo = new websiteAdZoneInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteAdZoneSelectOne", AdID);
                if (dr.Read())
                    setwebsiteAdZoneInfo(dr, ref _websiteAdZoneInfo);
                return _websiteAdZoneInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteAdZone
        /// </summary>
        /// <returns>Collection of websiteAdZoneInfo</returns>
        public static DataSet SelectAll()
        {
            DataSet ds = new DataSet();
            try
            {
                ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_mc_websiteAdZoneSelectAll");
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static DataSet SelectByFilter(string Info)
        {
            DataSet ds = new DataSet();
            try
            {
                ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_mc_websiteAdZoneSelectAllByInfo", Info);
                return ds;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteAdZonenfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteAdZoneInfo</returns>
        public static List<websiteAdZoneInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteAdZoneInfo> lstwebsiteAdZone = new List<websiteAdZoneInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteAdZoneSelectByFilters");
                setListwebsiteAdZoneInfo(ref dr, ref lstwebsiteAdZone);
                return lstwebsiteAdZone;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteAdZone
        /// </summary>
        /// <param name="websiteAdZoneInfo">Entity of websiteAdZone</param>
        /// <returns>error code</returns>
        public static int Insert(websiteAdZoneInfo _websiteAdZoneInfo)
        {
            try
            {
                return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_mc_websiteAdZoneInsert"
                                            , _websiteAdZoneInfo.AdName
                                            , _websiteAdZoneInfo.AdUrl
                                            , _websiteAdZoneInfo.AdBeginDate
                                            , _websiteAdZoneInfo.AdEndDate
                                            , _websiteAdZoneInfo.IsActive
                                            , _websiteAdZoneInfo.AdPosition
                                            , _websiteAdZoneInfo.AdDescription
                                            ));

            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Update websiteAdZone
        /// </summary>
        /// <param name="websiteAdZoneInfo">Entity of websiteAdZone</param>
        /// <returns>error code</returns>
        public static int Update(websiteAdZoneInfo _websiteAdZoneInfo)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteAdZoneUpdate"
                                            , _websiteAdZoneInfo.AdID
                                            , _websiteAdZoneInfo.AdName
                                            , _websiteAdZoneInfo.AdUrl
                                            , _websiteAdZoneInfo.AdBeginDate
                                            , _websiteAdZoneInfo.AdEndDate
                                            , _websiteAdZoneInfo.IsActive
                                            , _websiteAdZoneInfo.AdPosition
                                            , _websiteAdZoneInfo.AdDescription
                                            );
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="AdAction"></param>
        /// <returns></returns>
        public static int Publish(websiteAdZoneInfo _websiteAdZoneInfo, string AdAction)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteAdZonePublish"
                                            , _websiteAdZoneInfo.AdID
                                            , AdAction
                                            );
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="AdID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int AdID)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteAdZoneDelete", AdID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"

        private static void setListwebsiteAdZoneInfo(ref SqlDataReader dr, ref List<websiteAdZoneInfo> lstwebsiteAdZone)
        {
            websiteAdZoneInfo _websiteAdZoneInfo = null;
            while (dr.Read())
            {
                _websiteAdZoneInfo = new websiteAdZoneInfo();
                setwebsiteAdZoneInfo(dr, ref _websiteAdZoneInfo);
                lstwebsiteAdZone.Add(_websiteAdZoneInfo);
            }
        }

        private static void setwebsiteAdZoneInfo(SqlDataReader dr, ref websiteAdZoneInfo _websiteAdZoneInfo)
        {
            _websiteAdZoneInfo.AdID = dr[websiteAdZoneDAL.FIELD_ADID] != DBNull.Value ? Convert.ToInt32(dr[websiteAdZoneDAL.FIELD_ADID]) : 0;
            _websiteAdZoneInfo.AdName = dr[websiteAdZoneDAL.FIELD_ADNAME] != DBNull.Value ? Convert.ToString(dr[websiteAdZoneDAL.FIELD_ADNAME]) : string.Empty;
            _websiteAdZoneInfo.AdUrl = dr[websiteAdZoneDAL.FIELD_ADURL] != DBNull.Value ? Convert.ToString(dr[websiteAdZoneDAL.FIELD_ADURL]) : string.Empty;
            _websiteAdZoneInfo.AdBeginDate = dr[websiteAdZoneDAL.FIELD_ADBEGINDATE] != DBNull.Value ? Convert.ToDateTime(dr[websiteAdZoneDAL.FIELD_ADBEGINDATE]) : DateTime.MinValue;
            _websiteAdZoneInfo.AdEndDate = dr[websiteAdZoneDAL.FIELD_ADENDDATE] != DBNull.Value ? Convert.ToDateTime(dr[websiteAdZoneDAL.FIELD_ADENDDATE]) : DateTime.MinValue;
            _websiteAdZoneInfo.IsActive = dr[websiteAdZoneDAL.FIELD_ISACTIVE] != DBNull.Value ? Convert.ToBoolean(dr[websiteAdZoneDAL.FIELD_ISACTIVE]) : false;
            _websiteAdZoneInfo.AdPosition = dr[websiteAdZoneDAL.FIELD_ADPOSITION] != DBNull.Value ? Convert.ToInt32(dr[websiteAdZoneDAL.FIELD_ADPOSITION]) : 0;
            _websiteAdZoneInfo.AdDescription = dr[websiteAdZoneDAL.FIELD_ADDESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteAdZoneDAL.FIELD_ADDESCRIPTION]) : string.Empty;

        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteAdZone]";

        #endregion
    }
}

